#include <SDL/SDL.h>

#include "core/procinput.h"
#include "core/message.h"
#include "core/logger.h"

namespace engine {
		
	namespace core {
	
		ProcInput::ProcInput(shared_ptr<Kernel> parent):
		Process(parent, false) {
			
		}
		
		ProcInput::~ProcInput() {
			
		}
		
		bool ProcInput::prepare(float dT) {
			//We are only interested in input messages
			
			SDL_Event event;
 			while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_KEYDOWNMASK | SDL_KEYUPMASK)) {
				
				switch(event.type) {
					case SDL_KEYDOWN: {
						Logger::getLogger("kernel")->debug("Key down received");
						shared_ptr<Message> newMessage(new Message());
						
						//Catch an escape as a quit (for the moment)
						if (event.key.keysym.sym == SDLK_ESCAPE) {
							sendMessage(Message::createTermMessage());
							break;
						} else {												
							sendMessage(Message::createKeyPressMessage(event.key.keysym.sym));
						}
						
					} break;
					default:
						break;
				}
			}
			
			return true;
		}
		
		bool ProcInput::processRecievedMessage(shared_ptr<Message> msg) {
		
			return true;
		}
		
		void ProcInput::update() {
			
		}
		
		bool ProcInput::initialize() {
			return true;
		}
		
		void ProcInput::shutdown() {
			
		}
	}
}
